package com.example.a12502.aihome.equipment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a12502.aihome.R;

import java.util.ArrayList;
import java.util.HashMap;

public class EquipmentListViewAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<HashMap<String,Object>> data;
    EquipmentBean bean=null;


    public EquipmentListViewAdapter(Context context, ArrayList<HashMap<String,Object>> data){
        this.context=context;
        this.data=data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if(view==null){
            bean=new EquipmentBean();
            LayoutInflater layoutInflater=LayoutInflater.from(context);
            view=layoutInflater.inflate(R.layout.equipment_list,null);
            bean.ename=(TextView)view.findViewById(R.id.ename);
            bean.estatus=(TextView)view.findViewById(R.id.estatus);
            bean.econtrol=(ImageView)view.findViewById(R.id.econtrol);
            bean.linktext=(TextView)view.findViewById(R.id.linktext);
            bean.linkstatus=(ImageView)view.findViewById(R.id.linkstatus);
            view.setTag(bean);
        }else {
            bean=(EquipmentBean)view.getTag();
        }
        bean.ename.setText((String)data.get(position).get("ename"));
        bean.estatus.setText((String)data.get(position).get("estatus"));
        bean.linktext.setText((String)data.get(position).get("linktext"));
        bean.econtrol.setBackgroundResource((int)data.get(position).get("econtrol"));
        bean.linkstatus.setBackgroundResource((int)data.get(position).get("linkstatus"));

        return view;
    }
}
